//package com.nuonuo.util;
//
//import org.apache.http.HttpHost;
//import org.apache.http.NameValuePair;
//import org.apache.http.auth.AuthScope;
//import org.apache.http.auth.UsernamePasswordCredentials;
//import org.apache.http.client.CredentialsProvider;
//import org.apache.http.client.config.RequestConfig;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.client.protocol.HttpClientContext;
//import org.apache.http.impl.client.BasicCredentialsProvider;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.message.BasicNameValuePair;
//import org.springframework.aop.framework.ProxyConfig;
//
//import java.nio.charset.StandardCharsets;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
///**
// * @author duan
// * @version 1.0
// * @date 2023/11/21 19:06
// */
//public class HttpUtil {
//
//
//    /**
//     * 发送HTTP POST请求(电子发票回调)
//     * @param url
//     * @param map
//     * @return
//     */
//    public Object doPostProxy(String url, Map<String, String> map, ProxyConfig proxyConfig) {
//        Object obj;
//        CloseableHttpResponse response;
//        List<NameValuePair> list = new ArrayList<>();
//        // 设置代理HttpHost
//        HttpHost proxy = new HttpHost(proxyConfig.getHostname(), proxyConfig.getPort(), proxyConfig.getScheme());
//        // 设置认证
//        CredentialsProvider provider = new BasicCredentialsProvider();
//        provider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(proxyConfig.getUserName(), proxyConfig.getPassword()));
//        CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(getHttpConnection())
//                .setRetryHandler(httpSyncHandler()).setSSLContext(sslnoConfig()).setDefaultCredentialsProvider(provider)
//                .build();
//        HttpPost hpost = new HttpPost(url);
//        // 配置请求的超时设置
//        RequestConfig requestConfig = RequestConfig.custom()
//                .setConnectTimeout(DicConstants.ConnectTimeout)
//                .setSocketTimeout(DicConstants.SocketTimeout)
//                .setProxy(proxy)
//                .build();
//        hpost.setConfig(requestConfig);
//        hpost.addHeader(DicConstants.header_encode, StandardCharsets.UTF_8.name());
//        try {
//            Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
//            while (iterator.hasNext()) {
//                Map.Entry<String, String> elem = iterator.next();
//                list.add(new BasicNameValuePair(elem.getKey(), elem.getValue()));
//            }
//            hpost.setEntity(new UrlEncodedFormEntity(list, StandardCharsets.UTF_8.name()));
//            response = httpClient.execute(hpost, HttpClientContext.create());
//            try {
//                if (response.getStatusLine().getStatusCode() != 200) {
//                    logger.error("HttpConnUtil", "", "doPostProxy", "服务端post请求异常,响应码："+response.getStatusLine().getStatusCode());
//                    throw new Exception(ExConstants.http_invoke_Interrupt_Msg);
//                }
//                HttpEntity resEntity = response.getEntity();
//                obj = EntityUtils.toString(resEntity, Consts.UTF_8);
//                EntityUtils.consume(resEntity);
//            } finally {
//                response.close();
//            }
//        } catch (UnsupportedEncodingException e) {
//            logger.error("HttpConnUtil", "", "doPostProxy", "服务端post请求编码异常", e);
//            ResultMode result = new ResultMode();
//            result.setCode(ExConstants.code_Type);
//            result.setDescribe(ExConstants.code_Msg1);
//            return result;
//        } catch (Exception e) {
//            logger.error("HttpConnUtil", "", "doPostProxy", "API侧返回数据格式有误", e);
//            ResultMode result = new ResultMode();
//            result.setCode(ExConstants.input_Data_Type);
//            result.setDescribe(ExConstants.input_Data_param_Msg8);
//            return result;
//        } finally {
//            try {
//                httpClient.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return obj;
//    }
//}
